package org.example.book.config;

import lombok.extern.slf4j.Slf4j;
import org.example.book.model.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@ControllerAdvice
@ResponseBody
public class ErrorHandler {
    @ExceptionHandler
    public Result excption(Exception e) {
        log.error("发生异常,error:", e);
        return Result.fail("内部错误");
    }
    @ExceptionHandler
    public Result excption(NullPointerException e) {
        log.error("发生异常,error:", e);
        return Result.fail("NullPointerException异常，请联系管理员");
    }
    @ExceptionHandler
    public Result excption(ArithmeticException e) {
        log.error("发生异常,error:", e);
        return Result.fail("ArithmeticException异常，请联系管理员");
    }
}
